<template>
    <div class="box">
      <h2>Son1 子组件</h2>
      从vuex中获取的值: <label>{{ count }}</label>
      <div>{{ name }}</div>
      <br>
      <button @click="sub(1)">值 + 1</button>
      <button @click="change('修改成功')">一秒后修改</button>
      <button >{{ $store.getters.changeList }}</button>
      <div>{{user.user.name }}</div>
      <button @click="changeName">修改名字</button>
      <div>{{ $store.state.user.user.age }}</div>
      <button @click="changeAge">修改年龄</button>
      <div>{{$store.getters['user/changeList']}}</div>
    </div>
  </template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'Son1Com',
  computed: {
    ...mapState(['name', 'count']),
    ...mapState(['user'])
  },
  created () {
    console.log(this.$store.state.user.user.name)
  },
  methods: {
    sub () {
      this.$store.commit('sub', 1)
    },
    change (a) {
      this.$store.dispatch('changeAfter', a)
    },
    changeName () {
      this.$store.commit('user/changeName', 'violett')
    },
    changeAge () {
      this.$store.dispatch('user/changeAfter', 15)
    }
  }
}
</script>

  <style lang="css" scoped>
  .box{
    border: 3px solid #ccc;
    width: 400px;
    padding: 10px;
    margin: 20px;
  }
  h2 {
    margin-top: 10px;
  }
  </style>
